/*
 * Project: Daycare Web Application
 * Package: com.madetoordersoftware.daycare.business
 * File:    AuthenticationMgr
 * Created: Jun 3, 2010
 */

/*
 *  Copyright (c) 2010 Made 2 Order Software, LLC
 *
 *  All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 *  transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 *  You may not distribute the URL or redistribute the files to third parties. You may transfer the files
 *  onto a single storage device so long as you can prove ownership of the software. You may not reverse
 *  engineer, decompile, or disassemble the software or media files. You may not modify or translate the
 *  software or media, or distribute copies of the software or media without the written consent of Made
 *  2 Order Software
 */
package com.made2ordersoftware.daycare.business;

import com.made2ordersoftware.daycare.domain.PersonEntity;
import com.made2ordersoftware.daycare.exception.UnauthorizedUserException;
import com.made2ordersoftware.daycare.service.AuthenticationDao;
import com.made2ordersoftware.daycare.service.PersonDao;
import com.made2ordersoftware.exceptions.DAOException;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Class used to manage all actions performed with a Logging object.
 *
 * @author David Canning <dcannin@gmail.com>
 * @version 1.0.0
 */
@Stateless
public class AuthenticationMgr {

    private static final Logger LOG = LoggerFactory.getLogger(AuthenticationMgr.class);
    @EJB private AuthenticationDao lDao;
    @EJB private PersonDao pDao;

    /**
     * Authenticates the customer to the system.
     *
     * @param userName User name of person trying to login
     * @param password The password of the person trying to login
     *
     * @return A PersonEntity object representing the authenticated user.
     *
     * @throws UnauthorizedUserException If the username or password are incorrect.
     * @throws DAOException              Thrown if any exception from the DAO layer.
     */
    public PersonEntity authenticateUser(String userName, String password) throws UnauthorizedUserException,
            DAOException {
        LOG.info("Start authenticatePerson with user name {}", userName);
        PersonEntity user = lDao.authenticatePerson(userName, password);
        LOG.info("Finished authenticatePerson ...");
        return user;
    }

}
